package com.wkck.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wkck.domain.User;
import com.wkck.domain.UserSendResume;
import com.wkck.dto.ModifyUserPasswordDto;
import com.wkck.dto.QueryUserConditionDto;
import com.wkck.mapper.UserMapper;
import com.wkck.service.UserService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User getUserMsgByUserName(String username) {
        return userMapper.getUserMsgByUserName(username);
    }

    @Override
    public List<UserSendResume> getUserSendResumeMsg(Integer id) {
        return userMapper.getUserSendResumeMsg(id);
    }

    /**
     * @Author: CK
     * @Date: 2023/11/26
     * @Param: [queryUserConditionDto]
     * @return: 用户集合
     * @Description: 查询用户列表
     */
    @Override
    public IPage<User> queryByConditions(QueryUserConditionDto queryUserConditionDto) {

        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper
                .like(Strings.isNotEmpty(queryUserConditionDto.getName()),User::getName,queryUserConditionDto.getName())
                .eq(Strings.isNotEmpty(queryUserConditionDto.getSex()),User::getSex,queryUserConditionDto.getSex())
                .eq(Strings.isNotEmpty(queryUserConditionDto.getWork_status()),User::getWork_status,queryUserConditionDto.getWork_status());

        IPage<User> page = new Page<>(queryUserConditionDto.getCurrentPage(),queryUserConditionDto.getSize());

        return userMapper.selectPage(page,queryWrapper);
    }

    /**
     * @Author: CK
     * @Date: 2023/11/27
     * @Param: [modifyUserPasswordDto]
     * @return: 密码修改是否成功
     * @Description: 修改用户密码
     */
    @Override
    public Boolean modifyUserPassword(ModifyUserPasswordDto modifyUserPasswordDto) {

        LambdaUpdateWrapper<User> updateWrapper = new LambdaUpdateWrapper<>();

        updateWrapper.eq(User::getId, modifyUserPasswordDto.getId());
        updateWrapper.set(User::getPassword,modifyUserPasswordDto.getPassword());

        return this.update(updateWrapper);
    }

}
